package com.joplus.housekeeper.base;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import com.joplus.housekeeper.R;
import com.joplus.housekeeper.ui.view.absJoToolBar.AbsToolBar;
import com.joplus.housekeeper.ui.view.absJoToolBar.ToolsClickListener;
import com.joplus.housekeeper.ui.view.dialog.LoadingDialog2;


import me.imid.swipebacklayout.lib.app.SwipeBackActivity;


/**
 * Created by tangdehao on 2015/10/22.
 */
public abstract class BaseActivity extends SwipeBackActivity {


    public LoadingDialog2 loadingDialog;
    public AbsToolBar toolBar;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = this;


        //ExitAppUtils.getInstance().addActivity(this);
//        int statusBarColor = setTranslucentStatusColor();
//
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//            setTranslucentStatus(true);
//        }
//        SystemBarTintManager tintManager = new SystemBarTintManager(this);
//        tintManager.setStatusBarTintEnabled(true);
//        //使StatusBarTintView 和 actionbar的颜色保持一致，风格统一。
////        tintManager.setStatusBarTintResource(statusBarColor == -1 ? R.color.colorPrimary : statusBarColor);
//        tintManager.setStatusBarTintResource(R.color.statusBarColor);
//        // 设置状态栏的文字颜色
//        tintManager.setStatusBarDarkMode(true, this);
        loadingDialog = new LoadingDialog2(this);
        setContentView(initLayout());
        initViews(savedInstanceState);
        if (findViewById(R.id.toolbar2) != null) {
            toolBar = (AbsToolBar) findViewById(R.id.toolbar2);
            toolBar.setToolsClickListener(new ToolsClickListener() {
                @Override
                public void onLefeClick() {
                    leftClick();
                }

                @Override
                public void onRightClick() {

                }

                @Override
                public void onTittleClick() {

                }

                @Override
                public void onLeftExpClick() {

                }

                @Override
                public void onRightExpClick() {

                }
            });
        }
        initEvents();
        initDatas();

    }

   /* public void setTranslucentStatus(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }*/

    protected Context context;

    protected abstract int initLayout();

    protected abstract void initViews(Bundle savedInstanceState);

    protected abstract void initDatas();

    protected abstract void initEvents();

    /**
     * 是否滑动删除activity
     *
     * @return
     */
    protected abstract boolean isSlideFinishActivity();

    /**
     * 是否滑动删除activity
     *
     * @return
     */
    protected abstract int setTranslucentStatusColor();


    protected void startActivity(Class<?> cls) {
        startActivity(new Intent(this, cls));
    }

    protected void startActivityForIntent(Intent intent) {
        startActivity(intent);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onStart() {
        super.onStart();
        Uri mLink = getIntent().getData();

    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onPause() {
        super.onPause();
        if (loadingDialog!=null) {
            loadingDialog.dismiss();
        }

    }

    @Override
    protected void onRestart() {
        super.onRestart();

    }

    /**
     * 统一的左边的点击回调产生的事件，这里一般都是点击返回，所以直接关闭当前Activity，有特殊需求直接重写这个方法即可
     */
    protected void leftClick() {
        finish();
    }
}
